//
// Created by haoy on 2017/6/20.
//

#ifndef RTC_XSWITCH2_RTP_FEC_HPP
#define RTC_XSWITCH2_RTP_FEC_HPP

#include <cstdint>
#include <list>
#include <vector>

class FecHeader {
public:
    uint8_t e = 0;
    uint8_t l = 0;
    uint8_t p = 0;
    uint8_t x = 0;
    uint8_t cc = 0;
    uint8_t m = 0;
    uint8_t pt = 0;
    uint16_t seq = 0;  // 这个是sn_base 被保护的包的最小值
    uint32_t ts = 0;
    uint16_t len = 0;

    int read(const uint8_t* data, const int size);
    int write(uint8_t* data, const int size) const;
};

class FecLevelHeader {
public:
    uint16_t protection_len = 0;
    uint64_t mask = 0;
    std::list<uint16_t> protected_seqs;
    int read(const uint8_t* data, const int size, const uint8_t l);
    int write(uint8_t* data, const int size, const uint8_t l) const;
};

// currently only level 0 supported
class RtpFec {
public:
    FecHeader header;
    FecLevelHeader level_header;
    uint8_t* payload;
    int payload_size;

    int read(const uint8_t* data, const int size);
    int write(uint8_t* data, const int size) const;

};
#endif //RTC_XSWITCH2_RTP_FEC_HPP
